# -*- coding: utf-8 -*-
from django.db import models
from django.contrib import admin
from django.contrib.auth.models import User
import django.utils.timezone as timezone

# Create your models here.
""" delete by houchaoqun 20161128
STATUS_CHOICES = (
    ('d', 'Draft'),
    ('p', 'Published'),
    ('w', 'Withdrawn'),
)

class Article(models.Model):
    title = models.CharField(max_length=100)
    body = models.TextField()
    status = models.CharField(max_length=1, choices=STATUS_CHOICES)

    def __str__(self):              # __unicode__ on Python 2
        return self.title
"""

## author：Hou chaoqun
## function：create app_TuringClass's tables
## date：2016/11/22

class QuestionTag(models.Model):
    TagID = models.CharField(primary_key = True, max_length = 10, verbose_name = u'问题标签ID')
    TagName = models.CharField(max_length = 10, verbose_name = u'标签名称')
    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')

    def __unicode__(self):
        return self.TagID + '_' + self.TagName


class QuestionList(models.Model):
    QuestionID = models.IntegerField(primary_key = True, verbose_name = u'问题ID')
    QuestionAbstract = models.CharField(max_length = 200, verbose_name = u'问题摘要')
    QuestionContent = models.CharField(max_length = 2000, verbose_name = u'问题内容')
    TagsID = models.CharField(max_length = 100, verbose_name = u'问题标签ID')
    BrowseNum = models.IntegerField(default = 0, verbose_name = u'浏览次数')
    AnswerNum = models.IntegerField(default = 0, verbose_name = u'回答次数')
    PraiseNum = models.IntegerField(default = 0, verbose_name = u'点赞次数')
    OpposeNum = models.IntegerField(default = 0, verbose_name = u'反对次数')
    QuizzerID = models.CharField(default = 'default', max_length = 20, verbose_name = u'提问者ID')
    QuizzerName = models.CharField(default = 'default', max_length = 10, verbose_name = u'提问者昵称')
    LastModifyDate = models.DateTimeField(verbose_name = u'最后修改日期')
    QuestionCreateDate = models.DateTimeField(default = timezone.now, auto_now_add = True, verbose_name = u'提问日期')
    SupportByUserID = models.CharField(max_length = 5000, verbose_name = u'点赞用户ID串', null = True)          # 该问题被哪些用户点赞了
    NonSupportByUserID = models.CharField(max_length = 5000, verbose_name = u'不支持的用户ID串', null = True)   # 该问题被哪些用户踩了
    FocusByUserID = models.CharField(max_length = 5000, verbose_name = u'关注的标签ID串', null = True)          # 针对students,该问题被哪些用户收藏（关注）了
    Note = models.CharField(default = 'None', max_length = 100, verbose_name = u'备注')

    def __unicode__(self):
        return str(self.QuestionID) + '_' + self.QuizzerID + '_' + self.QuizzerName

## QuestionDetails表：
## 用户提交的问题先存入该表，默认状态“未审核”，等待管理员审核通过
## 审核通过后，存入QuestionList表，并显示在主页
QUESTION_STATUS = (
    ('Pending', '待审核'),
    ('Approved', '审核通过'),
    ('UnApproved', '未审核通过'),
)

class QuestionDetails(models.Model):
    QuestionID = models.IntegerField(primary_key = True, verbose_name = u'问题ID')
    QuestionAbstract = models.CharField(max_length = 200, verbose_name = u'问题摘要')
    QuestionContent = models.CharField(max_length = 10000, verbose_name = u'问题内容')
    QuizzerID = models.CharField(default = 'default', max_length = 20, verbose_name = '提问者ID')
    TagsID = models.CharField(default = 'default', max_length = 100, verbose_name = u'问题标签ID')
    QuestionStatus = models.CharField(default = 'Approved', max_length = 10, choices = QUESTION_STATUS)
    CheckerID = models.CharField(default = 'default', max_length = 20, verbose_name = '审核者ID')
    QuestionCheckDate = models.DateTimeField(default = timezone.now, auto_now_add = True, verbose_name = u'审核日期')
    Note = models.CharField(default = 'None', max_length = 100, verbose_name = u'备注')

    def __unicode__(self):
        return str(self.QuestionID) + '_' + self.QuestionAbstract + '_' + self.CheckerID + '_' + self.QuestionStatus

## 回答表 QuestionAnswers()
## 一个问题对应多个答案
## 一个答案对应一个问题
class QuestionAnswers(models.Model):
    AnswerID = models.CharField(primary_key = True, max_length = 20, verbose_name = u'答案ID')
    QuestionID = models.IntegerField(verbose_name = u'问题ID')
    AnswerContent = models.CharField(max_length = 10000, verbose_name = u'回答内容')
    ResponderID = models.CharField(max_length = 20, verbose_name = u'回答者ID')
    ResponderName = models.CharField(max_length = 20, verbose_name = u'回答者姓名')
    PraiseNum = models.IntegerField(default = 0, verbose_name = u'点赞次数')
    OpposeNum = models.IntegerField(default = 0, verbose_name = u'反对次数')
    SupportByUserID = models.CharField(max_length = 5000, verbose_name = u'点赞用户ID串', null = True)
    NonSupportByUserID = models.CharField(max_length = 5000, verbose_name = u'不支持的用户ID串', null = True)
    AnswerDate = models.DateTimeField(default = timezone.now, auto_now_add = True, verbose_name = u'答题日期')
    Note = models.CharField(default = 'None', max_length = 100, verbose_name = u'备注')

    def __unicode__(self):
        return str(self.QuestionID) + '_' + self.ResponderName

## author：Deng shi yan  
## checker: Hou chaoqun
## function：UploadingFiles
## date：2016/11/25
class UploadingFiles(models.Model):
    FileName = models.CharField(max_length = 300, verbose_name = u'文件名')
    UploaderID = models.CharField(max_length = 20, verbose_name = u'上传者ID')
    UploaderName = models.CharField(max_length = 20, verbose_name = u'上传者姓名')
    DownloadNum = models.IntegerField(default = 0, verbose_name = u'下载次数')
    UploadingDate = models.DateTimeField(default = timezone.now, auto_now_add = True, verbose_name = u'上传日期')
    Note = models.CharField(default = 'None', max_length = 100, verbose_name = u'备注')
    
    def __unicode__(self):
        return self.FileName + '_' + self.UploaderName


